package actionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import util.DomainUtils;

public class SearchContactGroupValidationForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String part_of_groupname = null;

	public String getPart_of_groupname() {
		return part_of_groupname;
	}

	public void setPart_of_groupname(String part_of_groupname) {
		this.part_of_groupname = 
				(part_of_groupname == null) ? "" : 
					DomainUtils.trim(part_of_groupname);
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.part_of_groupname = null;
	}
	
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		HttpSession session = request.getSession(false);


		//Checking session
		if(session == null || session.getAttribute(DomainUtils.CURRENT_USER_STRING) == null) {
			errors.add(
					DomainUtils.ALERT_ERROR_STRING,
					new ActionMessage(
							"session.error"));
			
			DomainUtils.keepParametersContent(request);
			
			return errors;
		}
		
//Jean-Luc: Permit to be empty for match all things
//		if (part_of_groupname == null || part_of_groupname.isEmpty()) {
//			errors.add(
//					"part_of_groupname",
//					new ActionMessage(
//							"search.notempty.error"));
//			
//			DomainUtils.keepParametersContent(request);
//			
//			return errors;
//		}
		
		return errors;	
	}

}
